package com {
	import flash.utils.getQualifiedClassName;

	/**
	 * MVC架构基类
	 * @author Liseen
	 */
	public class SuperBase {
		private var _superSubBaseList:Object;
		private var _frameProcessList:Object;
		private var _timerProcessList:Object;
		private var _nameHash:Object;

		public function SuperBase() {
			this._superSubBaseList = {};
			this._frameProcessList = {};
			this._timerProcessList = {};
			this._nameHash = {};
		}

		/**
		 * 获取完全限定名
		 */
		public function get sign():String {
			return getQualifiedClassName(this);
		}

		/**
		 * 添加到帧循环列表
		 * @param	key			键
		 * @param	callBack	回调方法
		 */
		public function addToFrameProcessList(key:String, callBack:Function):void {
			this._frameProcessList[key] = callBack;
		}

		/**
		 * 从帧循环列表中移除
		 * @param	key		键
		 */
		public function removeFromFrameProcessList(key:String):void {
			delete this._frameProcessList[key];
		}

		/**
		 * 循环帧列表
		 */
		public function frameProcess():void {
			var _key:String;
			for (_key in this._frameProcessList) {
				this._frameProcessList[_key]();
			}
		}

		/**
		 * 添加到时间处理列表
		 * @param	key			键
		 * @param	callBack	回调
		 */
		public function addToTimerProcessList(key:String, callBack:Function):void {
			this._timerProcessList[key] = callBack;
		}

		/**
		 * 从时间列表中移除
		 * @param	key
		 */
		public function removeFromTimerProcessList(key:String):void {
			delete this._timerProcessList[key];
		}

		/**
		 * 处理时间列表
		 */
		public function timerProcess():void {
			var _timeKey:String;
			for (_timeKey in this._timerProcessList) {
				this._timerProcessList[_timeKey]();
			}
		}

		/**
		 * 基础生成对象方法
		 * @param	classDef	类引用
		 * @param	name		名字
		 * @param	view		视图层引用
		 * @param	contrl		控制层引用
		 * @param	data		数据层引用
		 * @return				生成的对象
		 */
		protected function createObjectBase(classDef:Class, name:String, view:View, contrl:Controller, data:Data):Object {
			var className:String = this._nameHash[name];
			if (null == className) {
				className = name.replace(/^\[class /, "");
				className = (className.substring(0, 1).toLowerCase() + className.substring(1));
				this._nameHash[name] = className;
			}
			if (null == this._superSubBaseList[className]) {
				this._superSubBaseList[className] = new (classDef)();
				(this._superSubBaseList[className] as SuperSubBase).settle(className, view, contrl, data, this);
			}
			return this._superSubBaseList[className];
		}

		/**
		 * 销毁对象
		 * @param	key
		 */
		public function destroyObject(key:String):void {
			delete this._superSubBaseList[key];
		}

		/**
		 * 全部销毁
		 * @param	... _args
		 */
		public function destroyAllObject(... _args):void {
			var _local2:String;
			for (_local2 in this._superSubBaseList) {
				if (_args.indexOf(_local2) == -1) {
					this.destroyObject(_local2);
				}
			}
		}
	}

}
